package edu.software.cakehomework.service.impl;


import edu.software.cakehomework.dao.TypeRepository;
import edu.software.cakehomework.entity.Type;
import edu.software.cakehomework.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {

    @Autowired
    private TypeRepository typeRepository;

    @Override
    public List<Type> getAllTypes() {
        return typeRepository.findAll();
    }

    @Override
    public Type getTypeById(Integer id) {
        return typeRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("Type not found"));
    }

    @Override
    public Type getTypeByCategory(Type.Categories category) {
        return typeRepository.findByCategory(category)
                .orElseThrow(() -> new RuntimeException("Type not found"));
    }
}
